﻿using netDxf;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Tables;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestDxfDocument

{

    class ISYC_306_10
    {
        //图F.68  ISYC 306-10-全直径钻孔刀头麻花钻
        public static void ISYC_306_10_g(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中性线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            //基本参数-------------------------------------------------------------------------------------------------
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);

            //赋值参数--------------------------------------------------------------------------------------------------
            double sl_ = Convert.ToDouble(data["oal"]);
            double scale = Convert.ToDouble(data["scale"]);
         //    double sl_ = 150;
         //    double scale = 1;
            if (sl_ <= 67)
            {
                scale = 4;
            }
            else if (67 < sl_ && sl_ <= 75)
            {
                scale = 2.5;
            }
            else if (75 < sl_ && sl_ <= 100)
            {
                scale = 2;
            }
            else
            {
                scale = 1;
            }/*
            double dc = 10 * scale;
            double dconms = 13.2 * scale;
            double df = 14.75 * scale;
            double latth = 26 * scale;
            double lf = 29 * scale;
            double lu = 22.6 * scale;
            double lcf = 26.64 * scale;
            double ls = 24.54 * scale;
            double oal = 55.32 * scale;
            double lpr = oal - ls;
            double pl = lpr - lf;
            double sig_ = Math.Atan((dc / 2.0) / pl)*2;
            double sig = sig_ * 180 / pi;*/
            
            double dc = Convert.ToDouble(data["dc"]) * scale;
            double dconms = Convert.ToDouble(data["dconms"]) * scale;
            double df = Convert.ToDouble(data["df"]) * scale;
            double latth = Convert.ToDouble(data["latth"]) * scale;
            double lf = Convert.ToDouble(data["lf"]) * scale;
            double lu = Convert.ToDouble(data["lu"]) * scale;
            double lcf = Convert.ToDouble(data["lcf"]) * scale;
            double ls = Convert.ToDouble(data["ls"]) * scale;
            double oal = Convert.ToDouble(data["oal"]) * scale;
            double lpr = oal - ls;
            double pl = lpr - lf;
            double sig_ = Math.Atan((dc / 2.0) / pl) * 2;
            double sig = sig_ * 180 / pi;
            
            //点---------------------------------------------------------------------------------------------
            //第一部分
            //切削部分
            Vector2 p0 = new Vector2(0, 0);
            Vector2 p0_1 = fun.Polar(p0, pi, 5);
            Vector2 p0_2 = fun.Polar(p0, 0, oal + 5);
            Vector2 p1 = fun.Polar(p0, sig_ / 2, pl / Math.Cos(sig_ / 2)) ;
            Vector2 p2 = fun.Polar(p1, 0, lf - latth);
            Vector2 p3 = fun.mirrorpoint(p1, p0_1, p0_2);
            Vector2 p4 = fun.mirrorpoint(p2, p0_1, p0_2);
            Vector2 p5 = fun.Inters(p0_1, p0_2, p1, p3);
            Vector2 p6 = fun.Polar(p3, fun.CalAngle(p3, p0), (1.9 / 5.35 * fun.CalDistance(p0, p3)));
            //非切削部分
            Vector2 p7 = new Vector2(oal, 0);
            Vector2 p8 = fun.Polar(p7, pi / 2, dconms/2.0 - (dconms / 10.0));
            Vector2 p9 = fun.Polar(p8, pi - pi / 4, Math.Sqrt(Math.Pow(dconms / 20.0, 2) + Math.Pow(dconms / 20.0, 2)));
            Vector2 p10 = fun.Polar(p9, pi, ls - ls / 20.55 - dconms / 20.0) ;
            Vector2 p11 = fun.Polar(p10, pi / -2, dconms / 20.0);
            Vector2 p12 = fun.mirrorpoint(p8 , p0_1, p0_2);
            Vector2 p13 = fun.mirrorpoint(p9 , p0_1, p0_2);
            Vector2 p14 = fun.mirrorpoint(p10 , p0_1, p0_2);
            Vector2 p15 = fun.mirrorpoint(p11, p0_1, p0_2);
            //切削部分
            Vector2 p16 = new Vector2(lpr, 0);
            Vector2 p17 = fun.Polar(p16, pi / 2, df / 2.0);
            Vector2 p18 = fun.mirrorpoint(p17, p0_1, p0_2);
            Vector2 p19 = fun.Inters(p17, p18, p11, fun.Polar(p11, pi, ls));
            Vector2 p20 = fun.mirrorpoint(p19, p0_1, p0_2);
            Vector2 p21 = fun.Polar(p17, pi, lpr * (1.5 / 34.78));
            Vector2 p22 = fun.Polar(p21, pi / -2, 2.7 / 14.76 * df);
            Vector2 p23 = fun.Inters(p22, fun.Polar(p22, 0, ls), p17, p18);
            Vector2 p24 = fun.mirrorpoint(p21, p0_1, p0_2);
            Vector2 p25 = fun.mirrorpoint(p22, p0_1, p0_2);
            Vector2 p26 = fun.mirrorpoint(p23, p0_1, p0_2);
            Vector2 p27_1 = fun.Polar(p0, pi / 2, dc / 2.0);
            Vector2 p27_2 = fun.Polar(p27_1, 0, oal);
            Vector2 p27 = fun.Inters(p27_1, p27_2, p21, fun.Polar(p21, pi + pi / 4, ls));
            Vector2 p28 = fun.mirrorpoint(p27, p0_1, p0_2);
            Vector2 p29 = new Vector2(lcf, p28.Y);
            Vector2 arc1_1 = fun.Polar(p27, 0, (p22.X - p27.X) / 3.0);
            Vector2 arc1_2 = fun.mirrorpoint(arc1_1, p0_1, p0_2);
            Vector2 arc2_1 = fun.Polar(p27, pi / 2, 0.1);
            Vector2 arc2_2 = fun.Polar(arc2_1, pi, ls);
            Arc arc2 = fun.DrawArc5(p27, new Line(arc2_1, arc2_2), p5);
            Vector2 arc3_1 = fun.Polar(p5, 0, 0.1);
            Vector2 arc3_2 = fun.Polar(arc3_1, pi / -2, ls);
            Arc arc1 = fun.DrawArc5(p22, new Line(arc1_1, arc1_2), p25);
            Arc arc3 = fun.DrawArc5(p6, new Line(arc3_1, arc3_2), p5);
            Vector2 p30 = fun.Polar(p2, pi / -2, dc / 10.0);
            Vector2 p31 = fun.Inters1(p30, fun.Polar(p30, -1 * pi / 180, ls), arc2, 0);
            Vector2 p32 = fun.mirrorpoint(p30, p0_1, p0_2);
            Vector2 arc4_1 = fun.Polar(p30, pi / 2, 0.1);
            Vector2 arc4_2 = fun.Polar(arc4_1, 0, ls);
            Arc arc4 = fun.DrawArc5(p31, new Line(arc4_1, arc4_2), p30);
            Vector2 p33_1 = fun.Polar(fun.Polar(p0, pi / -2, dc), 0, lu) ;
            Vector2 p33_2 = fun.Polar(p33_1, pi / 2, ls);
            Vector2 p33 = fun.Inters(p29, fun.Polar(p29, 160 * pi / 180, ls), p33_1, p33_2);
            Vector2 arc5_1 = fun.Polar(p33, pi / 2, 0.1);
            Vector2 arc5_2 = fun.Polar(arc5_1, 0, ls);
            Arc arc5 = fun.DrawArc5(p29, new Line(arc5_1, arc5_2), p33);
            Vector2 arc6_1 = fun.Polar(p32, pi / -2, fun .CalDistance (p32,p4)/2.0);
            Vector2 arc6_2 = fun.Polar(arc6_1, 0, ls);
            Arc arc6 = fun.DrawArc5(p32, new Line(arc6_1, arc6_2), p33);
            Vector2 p34 = fun.Inters1(p29, fun.Polar(p29, 176 * pi / 180, ls), arc6, 1);
            var polyline1= Pus.AddPointsToLwPolyLine(p2, p1, p0, p5, p0, p6, p3, p4, p2) ;
            var polyline2 = Pus.AddPointsToLwPolyLine(p34,p29, p28, p24, p25, p26,p20,p15,p20, p18, p24, p18, p17, p21, p27, p28, p27, p21, p22, p23, p19, p11, p14,
                p13, p12, p8, p9, p13, p9, p10, p11, p19);
            dxf.AddEntity(new EntityObject[] { polyline1,polyline2
           ,arc1,arc2,arc3 ,arc4,arc5,arc6 
            }) ;
            fun.PolyFill(dxf, polyline1, 0.5, contour);
            fun.PolyFill(dxf, polyline2, 0.5, contour);
            fun.drawBArc(dxf, arc1, 0.5, contour);
            fun.drawBArc(dxf, arc2, 0.5, contour);
            fun.drawBArc(dxf, arc3, 0.5, contour);
            fun.drawBArc(dxf, arc4, 0.5, contour);
            fun.drawBArc(dxf, arc5, 0.5, contour);
            fun.drawBArc(dxf, arc6, 0.5, contour);
            //标注
            Vector2 v1 = fun.Inters(p29, p34, p33, fun.Polar(p33, pi / -2, ls));
            Vector2 v2 = fun.Polar(p10, 0, fun.CalDistance(p10, p9) / 4.0);
            Vector2 v3 = fun.Polar(p0, pi + pi / 4, dc * 2);
            Vector2 v4 = fun.Polar(p1, pi - 15 * pi / 180, 0.5 * 1.7 * scale);
            Vector2 v5 = fun.Polar(p0, pi + pi / 3, 0.5 * 1.7 * scale);
            Vector2 v6 = fun.Polar(v5, pi + pi / 3, dc );
            Vector2 v7 = fun.Polar(p16, pi / -4, 0.5 * 1.7 * scale);
            Vector2 v8 = fun.Polar(v7, pi / -4, dc*1.2 );
            fun.dimrot1(dxf, p2, p17,0, dc/2.0-(p17.Y -p2.Y )/2.0 , 2, 1.2 * scale, 1.6 * scale, 0.9, "LATTH", "", "");
            fun.dimrot1(dxf, p1, p17, 0, dc - (p17.Y - p1.Y) / 2.0 , 2, 1.2 * scale, 1.6 * scale, 0.9, "LF,LTA", "", "");
            fun.dimrot1(dxf, p0, p1, 0, dc + p1.Y/2.0, 2, 1.2 * scale, 1.6 * scale, 0.9, "PL", "", "");
            fun.dimrot1(dxf, p9, p13, -90, dc/2.0, 2, 1.2 * scale, 1.6 * scale, 0.9, "DCONMS", "", "");
            fun.dimrot1(dxf, p1, p3, 90, dc /2.0, 2, 1.2 * scale, 1.6 * scale, 0.9, "DC", "", "");
            fun.dimrot1(dxf, p0, v1 , 180, dc+v1.Y  /2.0, 2, 1.2 * scale, 1.6 * scale, 0.9, "LU", "", "");
            fun.dimrot1(dxf, p0, p29, 180, dc*1.5+p29.Y /2.0, 2, 1.2 * scale, 1.6 * scale, 0.9, "LCF", "", "");
            fun.dimrot1(dxf, p0, p18, 180, dc*2+p18.Y /2.0, 2, 1.2 * scale, 1.6 * scale, 0.9, "LPR", "", "");
            fun.dimrot1(dxf, p18, p12, 180, dc*2+(p18.Y -p12.Y )/2.0+p12.Y , 2, 1.2 * scale, 1.6 * scale, 0.9, "LS", "", "");
            fun.dimrot1(dxf, p0, p12, 180, dc*2.5+p12.Y/2.0 , 2, 1.2 * scale, 1.6 * scale, 0.9, "OAL", "", "");
            fun.dimrot1(dxf, p17, p18, -90, ls +dc/2.0+dc/2.5, 2, 1.2 * scale, 1.6 * scale, 0.9, "DF", "", "");
            fun.jdbz2(dxf, new Line(p0, p3), new Line(p0, p1), dc, 1.2 * scale, 1.6 * scale, 0.9, "SIG", "", "");
            fun.Axis(dxf, fun.Polar(p7, -70*pi/180, dc * 2), 0, -90, "Z", "X", "Y", 0.5 * scale, 1.6 * scale, 0);
            fun.Axis(dxf, p16, 0, -90, "", "", "", 0.5 * scale, 1.6 * scale, 0);
            fun.Axis(dxf, p0, 0, -90, "", "", "", 0.5 * scale, 1.6 * scale, 0);
            fun.Singlelinearrow(dxf, "CCMS", v2, 70, fun.Polar(v2, 70 * pi / 180, dc / 2.0), fun.Polar(v2, 70 * pi / 180, dc), 1.2 * scale, 1.6 * scale);
            fun.Singlelinearrow(dxf, "FDP",v3 , 180, fun.Polar(v3, 0 * pi / 180, dc / 2.0), fun.Polar(v3, 0 * pi / 180, dc), 1.2 * scale, 1.6 * scale);
            Line linev1 = new Line(v4, fun.Polar(v4, pi - 15 * pi / 180, dc / 4.0));
            Line linev2 = new Line(v5, v6 );
            Line linev3 = new Line(v7, v8);
            Text txt1 = new Text("CRP", fun.Polar(v4, pi - 15 * pi / 180, dc / 2.0), 1.2 * scale, 0);
            Text txt2 = new Text("CIP", fun.Polar(v6, pi /-2, 1.2 * scale),1.2*scale ,0);
            Text txt3 = new Text("PCS,MCS", fun.Polar(v8, pi / -2, 1.2 * scale), 1.2 * scale, 0);
            Text txt4 = new Text("ISYC=306_10", fun.Polar(p31 , pi / 2, dc*1.5), 1.2 * scale, 0);
            dxf.AddEntity(new EntityObject[] {linev1,linev2,linev3 
            ,txt1,txt2,txt3 ,txt4 
            });
            Line linev4 = new Line(p0_1, p0_2);
            linev4.Lineweight = Lineweight.W25;//Lineweight指线宽
            linev4.Layer = centre;//Layer指图层
            linev4.LinetypeScale = 5 * scale;//指线性比例
            linev4.Linetype = Linetype.DashDot;//Linetype指是点划线还是虚线什么的
            dxf.AddEntity(linev4); //提取

            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - 10 * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }


            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }

        ////图F.68  ISYC 306-10-全直径钻孔刀头麻花钻
        public static void ISYC_306_10_j(Dictionary<string, Object> data)
            {
                DxfDocument dxf = new DxfDocument();
                //图层
                Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
                Layer dimensioning = new Layer("dimensioning");    //尺寸层
                Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
                Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中性线
                Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
                Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
                Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
                Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
                Layer nocutting = new Layer("nocutting");    //非切削层
                Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
                Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
                Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
                Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
                Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
                Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
                Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
                Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

                //基本参数-------------------------------------------------------------------------------------------------
                double pi = Math.PI;
                string path = Convert.ToString(data["path"]);

                //值参数--------------------------------------------------------------------------------------------------
                double sl_ = Convert.ToDouble(data["oal"]);
                double scale = Convert.ToDouble(data["scale"]);
              //     double sl_ = 150;
              //     double scale = 1;
                if (sl_ <= 67)
                {
                    scale = 4;
                }
                else if (67 < sl_ && sl_ <= 75)
                {
                    scale = 2.5;
                }
                else if (75 < sl_ && sl_ <= 100)
                {
                    scale = 2;
                }
                else
                {
                    scale = 1;
                }/*
            double dc = 10 * scale;
            double dconms = 13.2 * scale;
            double df = 14.75 * scale;
            double latth = 26 * scale;
            double lf = 29 * scale;
            double lu = 22.6 * scale;
            double lcf = 26.64 * scale;
            double ls = 24.54 * scale;
            double oal = 55.32 * scale;
            double lpr = oal - ls;
            double pl = lpr - lf;
            double sig_ = Math.Atan((dc / 2.0) / pl)*2;
            double sig = sig_ * 180 / pi;
            */
                double dc = Convert.ToDouble(data["dc"]) * scale;
                double dconms = Convert.ToDouble(data["dconms"]) * scale;
                double df = Convert.ToDouble(data["df"]) * scale;
                double latth = Convert.ToDouble(data["latth"]) * scale;
                double lf = Convert.ToDouble(data["lf"]) * scale;
                double lu = Convert.ToDouble(data["lu"]) * scale;
                double lcf = Convert.ToDouble(data["lcf"]) * scale;
                double ls = Convert.ToDouble(data["ls"]) * scale;
                double oal = Convert.ToDouble(data["oal"]) * scale;
                double lpr = oal - ls;
                double pl = lpr - lf;
                double sig_ = Math.Atan((dc / 2.0) / pl) * 2;
                double sig = sig_ * 180 / pi;
            
                //点---------------------------------------------------------------------------------------------
                //第一部分
                //切削部分
                Vector2 p0 = new Vector2(0, 0);
                Vector2 p0_1 = fun.Polar(p0, pi, 5);
                Vector2 p0_2 = fun.Polar(p0, 0, oal + 5);
                Vector2 p1 = fun.Polar(p0, sig_ / 2, pl / Math.Cos(sig_ / 2));
                Vector2 p2 = fun.Polar(p1, 0, lf - latth);
                Vector2 p3 = fun.mirrorpoint(p1, p0_1, p0_2);
                Vector2 p4 = fun.mirrorpoint(p2, p0_1, p0_2);
                Vector2 p5 = fun.Inters(p0_1, p0_2, p1, p3);
                Vector2 p6 = fun.Polar(p3, fun.CalAngle(p3, p0), (1.9 / 5.35 * fun.CalDistance(p0, p3)));
                //非切削部分
                Vector2 p7 = new Vector2(oal, 0);
                Vector2 p8 = fun.Polar(p7, pi / 2, dconms / 2.0 - (dconms / 10.0));
                Vector2 p9 = fun.Polar(p8, pi - pi / 4, Math.Sqrt(Math.Pow(dconms / 20.0, 2) + Math.Pow(dconms / 20.0, 2)));
                Vector2 p10 = fun.Polar(p9, pi, ls - ls / 20.55 - dconms / 20.0);
                Vector2 p11 = fun.Polar(p10, pi / -2, dconms / 20.0);
                Vector2 p12 = fun.mirrorpoint(p8, p0_1, p0_2);
                Vector2 p13 = fun.mirrorpoint(p9, p0_1, p0_2);
                Vector2 p14 = fun.mirrorpoint(p10, p0_1, p0_2);
                Vector2 p15 = fun.mirrorpoint(p11, p0_1, p0_2);
                //切削部分
                Vector2 p16 = new Vector2(lpr, 0);
                Vector2 p17 = fun.Polar(p16, pi / 2, df / 2.0);
                Vector2 p18 = fun.mirrorpoint(p17, p0_1, p0_2);
                Vector2 p19 = fun.Inters(p17, p18, p11, fun.Polar(p11, pi, ls));
                Vector2 p20 = fun.mirrorpoint(p19, p0_1, p0_2);
                Vector2 p21 = fun.Polar(p17, pi, lpr * (1.5 / 34.78));
                Vector2 p22 = fun.Polar(p21, pi / -2, 2.7 / 14.76 * df);
                Vector2 p23 = fun.Inters(p22, fun.Polar(p22, 0, ls), p17, p18);
                Vector2 p24 = fun.mirrorpoint(p21, p0_1, p0_2);
                Vector2 p25 = fun.mirrorpoint(p22, p0_1, p0_2);
                Vector2 p26 = fun.mirrorpoint(p23, p0_1, p0_2);
                Vector2 p27_1 = fun.Polar(p0, pi / 2, dc / 2.0);
                Vector2 p27_2 = fun.Polar(p27_1, 0, oal);
                Vector2 p27 = fun.Inters(p27_1, p27_2, p21, fun.Polar(p21, pi + pi / 4, ls));
                Vector2 p28 = fun.mirrorpoint(p27, p0_1, p0_2);
                Vector2 p29 = new Vector2(lcf, p28.Y);
                Vector2 arc1_1 = fun.Polar(p27, 0, (p22.X - p27.X) / 3.0);
                Vector2 arc1_2 = fun.mirrorpoint(arc1_1, p0_1, p0_2);
            Vector2 j1 = fun.Inters(p21, p27, arc1_1, arc1_2);
            Vector2 j2 = fun.Inters(p28, p24, arc1_1, arc1_2);
                Vector2 arc2_1 = fun.Polar(p27, pi / 2, 0.1);
                Vector2 arc2_2 = fun.Polar(arc2_1, pi, ls);
                Arc arc2 = fun.DrawArc5(p27, new Line(arc2_1, arc2_2), p5);
                Vector2 arc3_1 = fun.Polar(p5, 0, 0.1);
                Vector2 arc3_2 = fun.Polar(arc3_1, pi / -2, ls);
                Arc arc1 = fun.DrawArc5(p22, new Line(arc1_1, arc1_2), p25);
                Arc arc3 = fun.DrawArc5(p6, new Line(arc3_1, arc3_2), p5);
                Vector2 p30 = fun.Polar(p2, pi / -2, dc / 10.0);
                Vector2 p31 = fun.Inters1(p30, fun.Polar(p30, -1 * pi / 180, ls), arc2, 0);
                Vector2 p32 = fun.mirrorpoint(p30, p0_1, p0_2);
                Vector2 arc4_1 = fun.Polar(p30, pi / 2, 0.1);
                Vector2 arc4_2 = fun.Polar(arc4_1, 0, ls);
                Arc arc4 = fun.DrawArc5(p31, new Line(arc4_1, arc4_2), p30);
                Vector2 p33_1 = fun.Polar(fun.Polar(p0, pi / -2, dc), 0, lu);
                Vector2 p33_2 = fun.Polar(p33_1, pi / 2, ls);
                Vector2 p33 = fun.Inters(p29, fun.Polar(p29, 160 * pi / 180, ls), p33_1, p33_2);
                Vector2 arc5_1 = fun.Polar(p33, pi / 2, 0.1);
                Vector2 arc5_2 = fun.Polar(arc5_1, 0, ls);
                Arc arc5 = fun.DrawArc5(p29, new Line(arc5_1, arc5_2), p33);
                Vector2 arc6_1 = fun.Polar(p32, pi / -2, fun.CalDistance(p32, p4) / 2.0);
                Vector2 arc6_2 = fun.Polar(arc6_1, 0, ls);
                Arc arc6 = fun.DrawArc5(p32, new Line(arc6_1, arc6_2), p33);
                Vector2 p34 = fun.Inters1(p29, fun.Polar(p29, 176 * pi / 180, ls), arc6, 1);
                var polyline1 = Pus.AddPointsToLwPolyLine(p2, p1, p0, p3, p4);
                var polyline2 = Pus.AddPointsToLwPolyLine(p1,p3,p28,j2,j1,j2, p24, p25, p26, p20, p15, p20, p18, p24, p18, p17, p21, p27, p28, p27,p2,p27, p21, p22,p25,p22, p23, p19, p11, p14,
                    p13, p12, p8, p9, p13, p9, p10, p11, p19);
            var polyline3 = Pus.AddPointsToLwPolyLine(p25, p23, p22, p26);
            dxf.AddEntity(new EntityObject[] { polyline1,polyline2,polyline3 
            });
                fun.PolyFill(dxf, polyline1, 1, contour);
                fun.PolyFill(dxf, polyline2, 0.5, contour);
            fun.PolyFill(dxf, polyline3, 0.35, contour);
            //标注
            Vector2 v1 = fun.Inters(p29, p34, p33, fun.Polar(p33, pi / -2, ls));
                fun.dimrot1(dxf, p2, p17, 0, dc  - (p17.Y - p2.Y) / 2.0, 2, 1.2 * scale, 1.6 * scale, 0.9, "LATTH", "", "");
                fun.dimrot1(dxf, p0, p1, 0, dc + p1.Y / 2.0, 2, 1.2 * scale, 1.6 * scale, 0.9, "PL", "", "");
                fun.dimrot1(dxf, p9, p13, -90, dc / 2.0, 2, 1.2 * scale, 1.6 * scale, 0.9, "DCONMS", "", "");
                fun.dimrot1(dxf, p1, p3, 90, dc / 2.0, 2, 1.2 * scale, 1.6 * scale, 0.9, "DC", "", "");
                fun.dimrot1(dxf, p0, v1, 180, dc + v1.Y / 2.0, 2, 1.2 * scale, 1.6 * scale, 0.9, "LU", "", "");
                fun.dimrot1(dxf, p0, p29, 180, dc * 1.5 + p29.Y / 2.0, 2, 1.2 * scale, 1.6 * scale, 0.9, "LCF", "", "");
                fun.dimrot1(dxf, p0, p18, 180, dc * 2 + p18.Y / 2.0, 2, 1.2 * scale, 1.6 * scale, 0.9, "LPR", "", "");
                fun.dimrot1(dxf, p18, p12, 180, dc * 2 + (p18.Y - p12.Y) / 2.0 + p12.Y, 2, 1.2 * scale, 1.6 * scale, 0.9, "LS", "", "");
                fun.dimrot1(dxf, p0, p12, 180, dc * 2.5 + p12.Y / 2.0, 2, 1.2 * scale, 1.6 * scale, 0.9, "OAL", "", "");
                fun.jdbz2(dxf, new Line(p0, p3), new Line(p0, p1), dc, 1.2 * scale, 1.6 * scale, 0.9, "SIG", "", "");
                
                Line linev4 = new Line(p0_1, p0_2);
                linev4.Lineweight = Lineweight.W25;//Lineweight指线宽
                linev4.Layer = centre;//Layer指图层
                linev4.LinetypeScale = 5 * scale;//指线性比例
                linev4.Linetype = Linetype.DashDot;//Linetype指是点划线还是虚线什么的
                dxf.AddEntity(linev4); //提取


            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - 10 * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }


            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
                dxf.Save(path);
            }
        }
}